package com.laiketui.admin.store.controller;

import com.laiketui.admin.store.api.BlockHomeModelService;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.core.lktconst.GloabConst;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.domain.vo.goods.GoodsConfigureVo;
import com.laiketui.domain.vo.saas.AddBlockGoodsVo;
import com.laiketui.domain.vo.saas.BlockManageVo;
import com.laiketui.root.annotation.HttpApiMethod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 后台----楼层管理
 *
 * @author gp
 * @date 2023/6/14
 */
@Api(tags = "后台-首页楼层管理")
@RestController
@RequestMapping("/admin/block")
public class BlockHomeController {
    @Autowired
    private BlockHomeModelService blockHomeModelService;

    @ApiOperation("添加楼层下的商品")
    @PostMapping("addOrDeleteGoods")
    @HttpApiMethod(apiKey = "admin.block.addOrDeleteGoodsWithBlock")
    public Result addOrDeleteGoodsWithBlock(AddBlockGoodsVo vo) {
        try {
            return Result.success(blockHomeModelService.addOrDeleteGoodsWithBlock(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("楼层管理列表显示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "楼层名称", dataType = "string", paramType = "form"),
    })
    @PostMapping("list")
    @HttpApiMethod(apiKey = "admin.block.list")
    public Result list(MainVo vo, String name) {
        try {
            return Result.success(blockHomeModelService.list(vo, name));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("单个楼层查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "楼层名称", dataType = "string", paramType = "form"),
    })
    @PostMapping("selectOne")
    @HttpApiMethod(apiKey = "admin.block.selectOne")
    public Result getBlockById(MainVo vo, String id) {
        try {
            return Result.success(blockHomeModelService.getBlockById(vo, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("新增首页楼层")
    @PostMapping("insert")
    @HttpApiMethod(apiKey = "admin.block.add")
    public Result add(BlockManageVo vo) {
        try {
            blockHomeModelService.add(vo);
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("获取指定楼层下的所有商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "楼层id", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "key", value = "商品id,条形码,商品名称", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "name", value = "商品名称", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "tradeModel", value = "贸易模式", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "isPlatform", value = "来源", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "cid", value = "分类id", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "bid", value = "品牌id", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "string", paramType = "form"),
    })
    @PostMapping("/goods")
    @HttpApiMethod(apiKey = "admin.block.getGoodsByBlock")
    public Result getGoodsByBlock(MainVo vo, String id, String key, String cid, String bid, Integer tradeModel, String isPlatform, String startTime, String endTime) {
        try {
            return Result.success(blockHomeModelService.getGoodsByBlock(vo, id, key, cid, bid, tradeModel, isPlatform, startTime, endTime));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }

    }

    @ApiOperation("删除楼层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "楼层名称", dataType = "int", paramType = "form"),
    })
    @PostMapping("deleteBlock")
    @HttpApiMethod(apiKey = "admin.block.deleteBlock")
    public Result deleteGoodsWithBlock(MainVo vo, String id) {
        try {
            blockHomeModelService.deleteBlock(vo, id);
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("删除楼层下的商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "楼层id", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "goodsIds", value = "商品id集", dataType = "int", paramType = "form"),
    })
    @PostMapping("delGoods")
    @HttpApiMethod(apiKey = "admin.block.delGoods")
    public Result delGoods(MainVo vo, String id, String goodsIds) {
        try {
            blockHomeModelService.delGoods(vo, id, goodsIds);
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("商品排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mappingId", value = "映射id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sort", value = "序号", dataType = "int", paramType = "form"),
    })
    @PostMapping("editSort")
    @HttpApiMethod(apiKey = "admin.block.editSort")
    public Result editSort(MainVo vo, int mappingId, int sort) {
        try {
            blockHomeModelService.editSort(vo, mappingId, sort);
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("楼层是否开启显示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "楼层id", dataType = "int", paramType = "form")
    })
    @PostMapping("enableOrNot")
    @HttpApiMethod(apiKey = "admin.block.EnableOrNot")
    public Result EnableOrNot(MainVo vo, String id) {
        try {
            blockHomeModelService.EnableOrNot(vo, id);
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("获取指定商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", dataType = "string", paramType = "form"),
    })
    @PostMapping("/getSpecifiedGoodsInfo")
    @HttpApiMethod(apiKey = "admin.block.GetSpecifiedGoodsInfo")
    public Result getSpecifiedGoodsInfo(GoodsConfigureVo vo, String id) {
        try {
            Map<String, Object> result = blockHomeModelService.getSpecifiedGoodsInfo(vo, id);
            return Result.success(result);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

}

